/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.controller.pay;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.admin.controller.GenericController;
import com.itttq.gshop.domain.po.PayApplyPo;
import com.itttq.gshop.domain.po.PayMethodPo;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.generic.connector.IPayApplyConnector;
import com.itttq.gshop.generic.connector.IPayMethodConnector;
import com.itttq.gshop.generic.util.Constants.PayStatus;

@RestController
@RequestMapping("pay/apply")
public class PayApplyController extends GenericController {
	private static final long serialVersionUID = 499162097633852075L;
	@Autowired
	private IPayApplyConnector payApplyConnector;
	@Autowired
	private IPayMethodConnector payMethodConnector;
	
	/**
	 * 根据条件查询PayApplyPo对象，并分页
	 * 
	 * @param payApply
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("applys.html")
	public ModelAndView getPayApplys(PayApplyPo payApply, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/pay/applys");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		payApply.setStart(ppt.getStart());
		payApply.setSize(ppt.getSize());
		ResultPageTo<PayApplyPo> rpt = payApplyConnector.getPayApplys(payApply);
		this.getPageMv("applys", mv, rpt);
		PayMethodPo pm = new PayMethodPo();
		pm.setSize(999);
		mv.addObject("payMethods", payMethodConnector.getPayMethods(pm));
		mv.addObject("payStatus", PayStatus.values());
		mv.addObject("apply", payApply);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addPayApply() {
		ModelAndView mv = new ModelAndView("/pay/applyAdd");
		
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param id
	 * @return
	 */
	@RequestMapping("view/{id}.html")
	public ModelAndView viewPayApply(@PathVariable("id") Integer id) {
		ModelAndView mv = addPayApply();
		if(id != null) {
			mv.addObject("apply", payApplyConnector.getPayApply(id));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param id
	 * @return
	 */
	@RequestMapping("edit/{id}.html")
	public ModelAndView editPayApply(@PathVariable("id") Integer id) {
		ModelAndView mv = viewPayApply(id);
		mv.addObject("op", "edit");
		return mv;
	}
	
//	/**
//	 * 保存PayApplyPo对象，无ID则新增，有ID则更新
//	 * 
//	 * @param payApply
//	 * @return
//	 * @Author 迷蝶
//	 * @return ModelAndView
//	 */
//	@RequestMapping("save.html")
//	public ModelAndView savePayApply(PayApplyPo payApply) {
//		payApplyConnector.savePayApply(payApply);
//		return getPayApplys(new PayApplyPo(), null);
//	}

	/**
	 * 根据ID删除PayApplyPo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{id}.html")
	@ResponseBody
	public ModelAndView delPayApply(@PathVariable("id") Integer id) {
		if(id != null) {
			payApplyConnector.delPayApply(id);
		}
		return getPayApplys(new PayApplyPo(), null);
	}
}